package org.jtzc.langchang4jdemo;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.output.Response;

/**
 * @author wu chuang
 * @description
 */
public class Demo2 {
    public static void main(String[] args) {

        ChatLanguageModel model = OpenAiChatModel.builder()
                .baseUrl("http://langchain4j.dev/demo/openai/v1")
                .apiKey("demo") //设置模型apiKey
                .modelName("gpt-4o-mini") //设置模型名称
                .build();
        UserMessage userMessage1 = UserMessage.userMessage("你好，我是小矩");
        ChatResponse chatResponse = model.chat(userMessage1);
        String text = chatResponse.aiMessage().text();
        System.out.println(text);
        System.out.println("----");

        // 下面一行代码是重点
        ChatResponse chatResponse2 = model.chat(userMessage1, chatResponse.aiMessage(), UserMessage.userMessage("我叫什么"));
        System.out.println(chatResponse2.aiMessage().text());

    }

}
